package com.cnap.service.impl;

import com.cnap.CnapApplicationTests;
import com.cnap.db.entity.ApplicationPO;
import com.cnap.db.entity.MicroServicePO;
import com.cnap.db.entity.StrategyPO;
import com.cnap.db.mapper.MicroServiceMapper;
import com.cnap.db.mapper.StrategyMapper;
import com.cnap.model.application.ApplicationLabel;
import com.cnap.model.exception.JsonException;
import com.cnap.model.schedule.ScaleStrategyDTO;
import com.cnap.model.schedule.StrategyDTO;
import com.cnap.model.schedule.StrategyTypeEnum;
import com.cnap.model.schedule.engine.CommentResultForEngine;
import com.cnap.model.schedule.engine.DeployPolicyCalcRes;
import com.cnap.model.schedule.engine.DeployPolicyRequest;
import com.cnap.model.schedule.engine.EngineClusterInfo;
import com.cnap.service.AlgorithmEngineService;
import com.cnap.service.ApplicationService;
import com.cnap.service.ClusterInfoService;
import com.cnap.service.ScheduleService;
import com.cnap.utils.JsonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <类文件描述>
 *
 * @author xc
 **/
class ScheduleServiceImplTest extends CnapApplicationTests {

    @Autowired
    private ScheduleService scheduleService;

    @MockBean
    private StrategyMapper strategyMapperMock;
    @MockBean
    private MicroServiceMapper microServiceMapperMock;
    @MockBean
    private AlgorithmEngineService algorithmEngineServiceMock;
    @MockBean
    private ApplicationService applicationServiceMock;
    @MockBean
    private ClusterInfoService clusterInfoServiceMock;

    @Test
    void addScheduleStrategyWithNoPermissions() {
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");

        List<StrategyDTO> strategyDTOList = Collections.singletonList(strategyDTO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("xc");

        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);


        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.addScheduleStrategy(strategyDTOList);
        });
    }
    @Test
    void addScheduleStrategyWithNoClusters() {
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");

        List<StrategyDTO> strategyDTOList = Collections.singletonList(strategyDTO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");
        microServicePO.setApplicationId("appId");
        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);

        String engineResponse = "{\"code\":200,\"message\":\"部署策略计算成功\",\"data\":{\"policy\":\"load\",\"actualPolicy\":\"load\",\"indicator\":\"cpu_usage,memory_usage\",\"recommendCloud\":\"Huawei\",\"userChooseCloud\":\"Huawei\",\"algDeployClusterInfos\":[{\"name\":\"huaweicloudv-tmp\",\"providerName\":\"Huawei\",\"ip\":\"172.17.4.69\",\"innerIp\":\"172.17.4.69\",\"resourceType\":\"exist\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":null,\"imageId\":null,\"regionId\":\"regionId\",\"zoneId\":\"zoneid\",\"sysDiskSize\":null,\"sysDiskType\":null,\"dataDisks\":null,\"bandwidth\":null,\"vmChargeType\":null,\"chargeUnit\":null,\"chargeCount\":null,\"eipChargeType\":null,\"cloudType\":null,\"cpu\":0,\"memory\":0,\"price\":\"0\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":200,\"msg\":\"successful deployment\"},{\"name\":null,\"providerName\":\"Aliyun\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"ecs.g5.xlarge\",\"imageId\":\"ubuntu_18_04_x64_20G_alibase_20220824.vhd\",\"regionId\":\"cn-zhangjiakou\",\"zoneId\":\"cn-zhangjiakou-a\",\"sysDiskSize\":100,\"sysDiskType\":\"cloud_ssd\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"PostPaid\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"PayByTraffic\",\"cloudType\":\"Aliyun\",\"cpu\":4,\"memory\":16,\"price\":\"1.33\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"},{\"name\":null,\"providerName\":\"Tencent\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"S5.LARGE8\",\"imageId\":\"img-pi0ii46r\",\"regionId\":\"ap-beijing\",\"zoneId\":\"ap-beijing-3\",\"sysDiskSize\":100,\"sysDiskType\":\"CLOUD_SSD\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"POSTPAID_BY_HOUR\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"TRAFFIC_POSTPAID_BY_HOUR\",\"cloudType\":\"Tencent\",\"cpu\":4,\"memory\":8,\"price\":\"0.66\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"}]}}";
        CommentResultForEngine<DeployPolicyCalcRes> result = JsonUtil.jsonStrToObject(engineResponse,
                new TypeReference<CommentResultForEngine<DeployPolicyCalcRes>>() {
                });
        Mockito.when(algorithmEngineServiceMock.calculateDeployPolicy(Mockito.any(DeployPolicyRequest.class))).thenReturn(result);

        ApplicationPO applicationPO = new ApplicationPO();
        ApplicationLabel label = new ApplicationLabel();
        label.setObjectScene(Arrays.asList("asd", "21"));
        label.setTechnology(Arrays.asList("asd", "34"));
        applicationPO.setLabel(label);
        Mockito.when(applicationServiceMock.selectByAppId("appId")).thenReturn(applicationPO);
        Mockito.doNothing().when(clusterInfoServiceMock).saveOrUpdateClusterInfo(Mockito.any(MicroServicePO.class), Mockito.anyList());

        scheduleService.addScheduleStrategy(strategyDTOList);

    }

    @Test
    void addScheduleStrategyWithNew() {
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");

        List<StrategyDTO> strategyDTOList = Collections.singletonList(strategyDTO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");
        microServicePO.setApplicationId("appId");
        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);

        String engineResponse = "{\"code\":200,\"message\":\"部署策略计算成功\",\"data\":{\"policy\":\"load\",\"actualPolicy\":\"load\",\"indicator\":\"cpu_usage,memory_usage\",\"recommendCloud\":\"Huawei\",\"userChooseCloud\":\"Huawei\",\"algDeployClusterInfos\":[{\"name\":\"huaweicloudv-tmp\",\"providerName\":\"Huawei\",\"ip\":\"172.17.4.69\",\"innerIp\":\"172.17.4.69\",\"resourceType\":\"exist\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":null,\"imageId\":null,\"regionId\":\"regionId\",\"zoneId\":\"zoneid\",\"sysDiskSize\":null,\"sysDiskType\":null,\"dataDisks\":null,\"bandwidth\":null,\"vmChargeType\":null,\"chargeUnit\":null,\"chargeCount\":null,\"eipChargeType\":null,\"cloudType\":null,\"cpu\":0,\"memory\":0,\"price\":\"0\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":200,\"msg\":\"successful deployment\"},{\"name\":null,\"providerName\":\"Aliyun\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"ecs.g5.xlarge\",\"imageId\":\"ubuntu_18_04_x64_20G_alibase_20220824.vhd\",\"regionId\":\"cn-zhangjiakou\",\"zoneId\":\"cn-zhangjiakou-a\",\"sysDiskSize\":100,\"sysDiskType\":\"cloud_ssd\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"PostPaid\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"PayByTraffic\",\"cloudType\":\"Aliyun\",\"cpu\":4,\"memory\":16,\"price\":\"1.33\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"},{\"name\":null,\"providerName\":\"Tencent\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"S5.LARGE8\",\"imageId\":\"img-pi0ii46r\",\"regionId\":\"ap-beijing\",\"zoneId\":\"ap-beijing-3\",\"sysDiskSize\":100,\"sysDiskType\":\"CLOUD_SSD\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"POSTPAID_BY_HOUR\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"TRAFFIC_POSTPAID_BY_HOUR\",\"cloudType\":\"Tencent\",\"cpu\":4,\"memory\":8,\"price\":\"0.66\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"}]}}";
        CommentResultForEngine<DeployPolicyCalcRes> result = JsonUtil.jsonStrToObject(engineResponse,
                new TypeReference<CommentResultForEngine<DeployPolicyCalcRes>>() {
                });
        Mockito.when(algorithmEngineServiceMock.calculateDeployPolicy(Mockito.any(DeployPolicyRequest.class))).thenReturn(result);

        ApplicationPO applicationPO = new ApplicationPO();
        ApplicationLabel label = new ApplicationLabel();
        label.setObjectScene(Arrays.asList("asd", "21"));
        label.setTechnology(Arrays.asList("asd", "34"));
        applicationPO.setLabel(label);
        Mockito.when(applicationServiceMock.selectByAppId("appId")).thenReturn(applicationPO);

        Mockito.when(strategyMapperMock.insertStrategy(Mockito.any(StrategyPO.class))).thenReturn(1);
        //Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType(Mockito.anyString(),
        //StrategyTypeEnum.SCALE_STRATEGY.getValue())).thenReturn(null);

        //Mockito.doNothing().when(clusterInfoServiceMock).saveOrUpdateClusterInfo(Mockito.any(), Mockito.anyList());

        Assertions.assertDoesNotThrow(()->{
            scheduleService.addScheduleStrategy(strategyDTOList);
        });
    }
    @Test
    void addScheduleStrategyWithUpdate() {
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");

        List<StrategyDTO> strategyDTOList = Collections.singletonList(strategyDTO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");
        microServicePO.setApplicationId("appId");
        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);

        String engineResponse = "{\"code\":200,\"message\":\"部署策略计算成功\",\"data\":{\"policy\":\"load\",\"actualPolicy\":\"load\",\"indicator\":\"cpu_usage,memory_usage\",\"recommendCloud\":\"Huawei\",\"userChooseCloud\":\"Huawei\",\"algDeployClusterInfos\":[{\"name\":\"huaweicloudv-tmp\",\"providerName\":\"Huawei\",\"ip\":\"172.17.4.69\",\"innerIp\":\"172.17.4.69\",\"resourceType\":\"exist\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":null,\"imageId\":null,\"regionId\":\"regionId\",\"zoneId\":\"zoneid\",\"sysDiskSize\":null,\"sysDiskType\":null,\"dataDisks\":null,\"bandwidth\":null,\"vmChargeType\":null,\"chargeUnit\":null,\"chargeCount\":null,\"eipChargeType\":null,\"cloudType\":null,\"cpu\":0,\"memory\":0,\"price\":\"0\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":200,\"msg\":\"successful deployment\"},{\"name\":null,\"providerName\":\"Aliyun\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"ecs.g5.xlarge\",\"imageId\":\"ubuntu_18_04_x64_20G_alibase_20220824.vhd\",\"regionId\":\"cn-zhangjiakou\",\"zoneId\":\"cn-zhangjiakou-a\",\"sysDiskSize\":100,\"sysDiskType\":\"cloud_ssd\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"PostPaid\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"PayByTraffic\",\"cloudType\":\"Aliyun\",\"cpu\":4,\"memory\":16,\"price\":\"1.33\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"},{\"name\":null,\"providerName\":\"Tencent\",\"ip\":null,\"innerIp\":null,\"resourceType\":\"create\",\"createVmInfos\":[],\"clusterDetails\":[{\"name\":null,\"flavorId\":\"S5.LARGE8\",\"imageId\":\"img-pi0ii46r\",\"regionId\":\"ap-beijing\",\"zoneId\":\"ap-beijing-3\",\"sysDiskSize\":100,\"sysDiskType\":\"CLOUD_SSD\",\"dataDisks\":null,\"bandwidth\":10,\"vmChargeType\":\"POSTPAID_BY_HOUR\",\"chargeUnit\":\"Month\",\"chargeCount\":3,\"eipChargeType\":\"TRAFFIC_POSTPAID_BY_HOUR\",\"cloudType\":\"Tencent\",\"cpu\":4,\"memory\":8,\"price\":\"0.66\",\"priceDescribe\":\"元\",\"priceShowUnit\":\"hour\",\"code\":0,\"msg\":null}],\"code\":400,\"msg\":\"require new cluster and vm resources\"}]}}";
        CommentResultForEngine<DeployPolicyCalcRes> result = JsonUtil.jsonStrToObject(engineResponse,
                new TypeReference<CommentResultForEngine<DeployPolicyCalcRes>>() {
                });
        Mockito.when(algorithmEngineServiceMock.calculateDeployPolicy(Mockito.any(DeployPolicyRequest.class))).thenReturn(result);

        ApplicationPO applicationPO = new ApplicationPO();
        ApplicationLabel label = new ApplicationLabel();
        label.setObjectScene(Arrays.asList("asd", "21"));
        label.setTechnology(Arrays.asList("asd", "34"));
        applicationPO.setLabel(label);
        Mockito.when(applicationServiceMock.selectByAppId("appId")).thenReturn(applicationPO);

        Mockito.when(strategyMapperMock.insertStrategy(Mockito.any(StrategyPO.class))).thenReturn(1);
        StrategyPO oldSchedule = new StrategyPO();

        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCHEDULE_STRATEGY.getValue())).thenReturn(oldSchedule);

        //Mockito.doNothing().when(clusterInfoServiceMock).saveOrUpdateClusterInfo(Mockito.any(), Mockito.anyList());

        Assertions.assertDoesNotThrow(()->{
            scheduleService.addScheduleStrategy(strategyDTOList);
        });
    }
    @Test
    void addScaleStrategyWithNoSchedule() {
        ScaleStrategyDTO scaleStrategyDTO = new ScaleStrategyDTO();
        scaleStrategyDTO.setServiceId("svcId");
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");
        scaleStrategyDTO.setStrategys(Collections.singletonList(strategyDTO));


        List<ScaleStrategyDTO> strategyDTOList = Collections.singletonList(scaleStrategyDTO);

        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCHEDULE_STRATEGY.getValue())).thenReturn(null);

        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.addScaleStrategy(strategyDTOList);
        });
    }

    @Test
    void addScaleStrategyWithNoPermissions() {
        ScaleStrategyDTO scaleStrategyDTO = new ScaleStrategyDTO();
        scaleStrategyDTO.setServiceId("svcId");
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");
        scaleStrategyDTO.setStrategys(Collections.singletonList(strategyDTO));


        List<ScaleStrategyDTO> strategyDTOList = Collections.singletonList(scaleStrategyDTO);

        StrategyPO strategyPO = new StrategyPO();
        strategyPO.setClusterInfos(Collections.singletonList(new EngineClusterInfo()));
        strategyPO.setServiceId("svcId");
        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCHEDULE_STRATEGY.getValue())).thenReturn(strategyPO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("as");

        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);

        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.addScaleStrategy(strategyDTOList);
        });
    }

    @Test
    void addScaleStrategyWithNew() {
        ScaleStrategyDTO scaleStrategyDTO = new ScaleStrategyDTO();
        scaleStrategyDTO.setServiceId("svcId");
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");
        scaleStrategyDTO.setStrategys(Collections.singletonList(strategyDTO));


        List<ScaleStrategyDTO> strategyDTOList = Collections.singletonList(scaleStrategyDTO);

        StrategyPO strategyPO = new StrategyPO();
        strategyPO.setClusterInfos(Collections.singletonList(new EngineClusterInfo()));
        strategyPO.setServiceId("svcId");
        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCHEDULE_STRATEGY.getValue())).thenReturn(strategyPO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");

        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);
        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCALE_STRATEGY.getValue())).thenReturn(null);


        Assertions.assertDoesNotThrow(()->{
            scheduleService.addScaleStrategy(strategyDTOList);
        });
    }
    @Test
    void addScaleStrategyWithUpdate() {
        ScaleStrategyDTO scaleStrategyDTO = new ScaleStrategyDTO();
        scaleStrategyDTO.setServiceId("svcId");
        StrategyDTO strategyDTO = new StrategyDTO();
        strategyDTO.setServiceId("svcId");
        strategyDTO.setStrategyName("load");
        strategyDTO.setEnableDefault(1);
        strategyDTO.setParams("params");
        scaleStrategyDTO.setStrategys(Collections.singletonList(strategyDTO));


        List<ScaleStrategyDTO> strategyDTOList = Collections.singletonList(scaleStrategyDTO);

        StrategyPO strategyPO = new StrategyPO();
        strategyPO.setClusterInfos(Collections.singletonList(new EngineClusterInfo()));
        strategyPO.setServiceId("svcId");
        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCHEDULE_STRATEGY.getValue())).thenReturn(strategyPO);

        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");

        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);
        StrategyPO oldScale = new StrategyPO();
        Mockito.when(strategyMapperMock.selectStrategyByServiceIdAndType("svcId",
                StrategyTypeEnum.SCALE_STRATEGY.getValue())).thenReturn(oldScale);


        Assertions.assertDoesNotThrow(()->{
            scheduleService.addScaleStrategy(strategyDTOList);
        });
    }
    @Test
    void deleteStrategyByIdWithNullStrategy() {
        Mockito.when(strategyMapperMock.selectStrategyById("id")).thenReturn(null);

        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.deleteStrategyById("id");
        });
    }

    @Test
    void deleteStrategyByIdWithNullMicro() {
        Mockito.when(strategyMapperMock.selectStrategyById("id")).thenReturn(Mockito.mock(StrategyPO.class));
        Mockito.when(microServiceMapperMock.selectMicroServiceById(Mockito.anyString())).thenReturn(null);
        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.deleteStrategyById("id");
        });
    }

    @Test
    void deleteStrategyByIdWithNoPermission() {
        StrategyPO strategyPO = new StrategyPO();
        strategyPO.setServiceId("svcId");
        Mockito.when(strategyMapperMock.selectStrategyById("id")).thenReturn(strategyPO);
        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("xc");
        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);
        Assertions.assertThrows(JsonException.class, () -> {
            scheduleService.deleteStrategyById("id");
        });
    }

    @Test
    void deleteStrategyById() {
        StrategyPO strategyPO = new StrategyPO();
        strategyPO.setId("id");
        strategyPO.setServiceId("svcId");
        Mockito.when(strategyMapperMock.selectStrategyById("id")).thenReturn(strategyPO);
        MicroServicePO microServicePO = new MicroServicePO();
        microServicePO.setUserName("admin");
        Mockito.when(microServiceMapperMock.selectMicroServiceById("svcId")).thenReturn(microServicePO);
        Mockito.when(strategyMapperMock.deleteStrategyById("id")).thenReturn(1);
        boolean result = scheduleService.deleteStrategyById("id");
        Assertions.assertTrue(result);
    }
}